//
//  CourseClassMenuCell.m
//  ShowYork
//
//  Created by hxh on 2020/8/28.
//  Copyright © 2020 hxh. All rights reserved.
//

#import "LessonClassMenuCell.h"

@interface LessonClassMenuCell ()
@property (nonatomic,strong)UIView *chineseView;
@property (nonatomic,strong)UIView *mathView;
@property (nonatomic,strong)UIView *englishView;
@property (nonatomic,strong)UIButton *chineseBtn;
@property (nonatomic,strong)UIButton *mathBtn;
@property (nonatomic,strong)UIButton *englishBtn;
@property (nonatomic,strong)UILabel *chineseLb;
@property (nonatomic,strong)UILabel *mathLb;
@property (nonatomic,strong)UILabel *englishLb;


@end

@implementation LessonClassMenuCell

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        [self setUI];
    }
    return self;
}
- (void)setUI{
    
    self.contentView.backgroundColor = UIColor.clearColor;
    self.backgroundColor = UIColor.clearColor;
    
    self.chineseView = [[UIView alloc]init];
    [self.contentView addSubview:self.chineseView];
        
    self.mathView = [[UIView alloc]init];
    [self.contentView addSubview:self.mathView];
    
    self.englishView = [[UIView alloc]init];
    [self.contentView addSubview:self.englishView];
    
    self.chineseBtn = [[UIButton alloc]init];
    self.chineseBtn.tag = 1;
    [self.chineseBtn setImage:[UIImage imageNamed:@"course_chinese"] forState:UIControlStateNormal];
    [self.chineseBtn addTarget:self action:@selector(menuMethod:) forControlEvents:UIControlEventTouchUpInside];
    [self.contentView addSubview:self.chineseBtn];
        
    self.mathBtn = [[UIButton alloc]init];
    self.mathBtn.tag = 2;
    [self.mathBtn setImage:[UIImage imageNamed:@"course_math"] forState:UIControlStateNormal];
    [self.mathBtn addTarget:self action:@selector(menuMethod:) forControlEvents:UIControlEventTouchUpInside];
    [self.contentView addSubview:self.mathBtn];
    
    self.englishBtn = [[UIButton alloc]init];
    self.englishBtn.tag = 3;
    [self.englishBtn setImage:[UIImage imageNamed:@"course_english"] forState:UIControlStateNormal];
    [self.englishBtn addTarget:self action:@selector(menuMethod:) forControlEvents:UIControlEventTouchUpInside];
    [self.contentView addSubview:self.englishBtn];
    
    self.chineseLb = [[UILabel alloc]init];
    self.chineseLb.text = @"语文";
    self.chineseLb.textColor = RGBA(51, 51, 51, 1);
    self.chineseLb.font = font(12);
    [self.chineseView addSubview:self.chineseLb];
    
    self.mathLb = [[UILabel alloc]init];
    self.mathLb.text = @"数学";
    self.mathLb.textColor = RGBA(51, 51, 51, 1);
    self.mathLb.font = font(12);
    [self.mathView addSubview:self.mathLb];
    
    
    self.englishLb = [[UILabel alloc]init];
    self.englishLb.text = @"英语";
    self.englishLb.textColor = RGBA(51, 51, 51, 1);
    self.englishLb.font = font(12);
    [self.englishView addSubview:self.englishLb];
    
    
    [self.chineseView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.contentView);
        make.right.equalTo(self.mathView.mas_left);
        make.width.mas_equalTo(self.mathView);
        make.height.mas_equalTo(100).priorityHigh();
        make.top.equalTo(self.contentView);
        make.bottom.equalTo(self.contentView).offset(-20);
    }];
    
    [self.chineseBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.center.equalTo(self.chineseView);
    }];
    [self.mathBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.center.equalTo(self.mathView);
    }];
    [self.englishBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.center.equalTo(self.englishView);
    }];
    
    [self.mathView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.chineseView.mas_right);
        make.right.equalTo(self.englishView.mas_left);
        make.top.height.width.mas_equalTo(self.englishView);
        
    }];
    
    [self.englishView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.mathView.mas_right);
        make.right.equalTo(self.contentView);
        make.top.height.width.mas_equalTo(self.chineseView);
    }];
    [self.chineseLb mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.equalTo(self.chineseBtn);
        make.top.equalTo(self.chineseView.mas_bottom).offset(-15);
    }];
    [self.mathLb mas_makeConstraints:^(MASConstraintMaker *make) {
         make.centerX.equalTo(self.mathBtn);
         make.centerY.equalTo(self.chineseLb);
     }];
    [self.englishLb mas_makeConstraints:^(MASConstraintMaker *make) {
         make.centerX.equalTo(self.englishBtn);
         make.centerY.equalTo(self.chineseLb);
     }];
}
+(instancetype)cellWithTableView:(UITableView *)tableView{
    NSString *ID = @"LessonClassMenuCell";
    LessonClassMenuCell *cell = [tableView dequeueReusableCellWithIdentifier:ID];
    if (!cell) {
        cell = [[LessonClassMenuCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:ID];
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
    }
    return cell;
}

- (void)menuMethod:(UIButton *)btn{
    if (self.delegate && [self.delegate respondsToSelector:@selector(showMenuListAtType:)]) {
        [self.delegate showMenuListAtType:btn.tag];
    }
}

@end
